const indexTpl = require('../views/index.html')
import index   from './index'
import allpage from './allpage'
import recent from './recent'
import Bscroll from 'better-scroll';

class RenderPage{
    constructor(){
        
        this.renderIndex();
        this.changeHash();
        //this.renderConcert();
    }
    renderIndex(){
        // location.hash = "index";

        // location.reload();
        // console.log(swp);
        $("#root").html(indexTpl);
        // console.log(document.querySelector('.swiper-container'));
        // require('./controlswiper');
        
        index.render(); 
        recent.render();
        this.addIndexEvent();
        this.addRecentEvent();
    }

    addRecentEvent(){
        $('.show-week').on("click",'span',function(){
            //console.log($(this).attr('id'));
            $(this).addClass('active').siblings().removeClass('active');
            //console.log(recent);
            recent.render($(this).attr('id'));
            
        })
    }

    changeHash(){
        $(window).on("hashchange",() => {
            
            let hash = location.hash && location.hash.substr(1) || 'index';
            //console.log(hash);
            switch(hash){
                case "concert"     : this.renderConcert();     break;
                case "index"       : this.renderIndex();location.reload();break;
                case "opera"       : this.renderOpera();       break;
                case "music"       : this.renderMusic();       break;
                case "physical"    : this.renderPhysical();    break;
                case "comic"       : this.renderComic();       break;
                case "parentchild" : this.renderParentchild(); break;
                case "relax"       : this.renderRelax();       break;
                case "oversea"     : this.renderOversea();     break;
                // case "opera"  : 
                default:"";
            }
        })
        $(window).on("load",() => {
            let hash =location.hash && location.hash.substr(1) || 'index';
            //console.log(hash);
            switch(hash){
                case "concert"     : this.renderConcert();     break;
                case "index"       : this.renderIndex();       break;
                case "opera"       : this.renderOpera();       break;
                case "music"       : this.renderMusic();       break;
                case "physical"    : this.renderPhysical();    break;
                case "comic"       : this.renderComic();       break;
                case "parentchild" : this.renderParentchild(); break;
                case "relax"       : this.renderRelax();       break;
                case "oversea"     : this.renderOversea();     break; 
                default:"";
            }
        })
    }


    renderConcert(){
        allpage.render();
        allpage.renderConcertPage();
    }

    renderOpera(){
        allpage.render();
        allpage.renderOpera();
    }
    renderMusic(){
        allpage.render();
        allpage.renderMusic();
    }
    renderPhysical(){
        allpage.render();
        allpage.renderPhysical();
    }
    renderComic(){
        allpage.render();
        allpage.renderComic();
    }
    renderParentchild(){
        allpage.render();
        allpage.renderParent();
    }
    renderRelax(){
        allpage.render();
        allpage.renderRelax();
    }
    renderOversea(){
        allpage.render();
        allpage.renderOversea();
    }
    addIndexEvent(){
        // console.log(document.querySelector(".dm-classify"));
        $(".dm-classify li").on("click",function () {
            let hashdata  = $(this).attr('data-hash');
            location.hash = hashdata;          
        })
        
    }
}

new RenderPage();